#pragma once

#include<iostream>
#include <string>
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#define FIFO_FILE "./myfifo"
#define MODE 0664

enum
{
    FIFO_CREATE_ERR = 1,
    FIFO_DELETE_ERR,
    FIFO_OPEN_ERR
};

// 将管道封装在Init类中方便初始化和销毁
struct Init
{
    Init()
    {
        int n = mkfifo(FIFO_FILE, MODE);
        if (n < 0)
        {
            perror("mkfifo fail");
            exit(FIFO_CREATE_ERR);
        }
    }

    ~Init()
    {
        int n = unlink(FIFO_FILE);
        if (n < 0)
        {
            perror("unlink fail");
            exit(FIFO_DELETE_ERR);
        }
    }
};